package com.ruoyi.web.controller.littleRedBook;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.littleRedBook.domain.pojo.Employee;
import com.ruoyi.littleRedBook.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * <p>
 * 员工表 前端控制器
 * </p>
 *
 * @author
 * @since 2025-09-10
 */
@RestController
@RequestMapping("/api/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 新增员工
     */
    @PostMapping
    public AjaxResult add(@RequestBody Employee employee) {
        return AjaxResult.success(employeeService.save(employee));
    }

    /**
     * 修改员工
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Employee employee) {
        return AjaxResult.success(employeeService.updateById(employee));
    }

    /**
     * 删除员工
     */
    @DeleteMapping("/{employeeIds}")
    public AjaxResult remove(@PathVariable Long[] employeeIds) {
        return AjaxResult.success(employeeService.removeByIds(Arrays.asList(employeeIds)));
    }

    /**
     * 查询员工详情
     */
    @GetMapping("/{employeeId}")
    public AjaxResult getInfo(@PathVariable Long employeeId) {
        return AjaxResult.success(employeeService.getById(employeeId));
    }

    /**
     * 查询员工列表
     */
    @GetMapping
    public AjaxResult list() {
        return AjaxResult.success(employeeService.list());
    }
}
